<?php
	class DATABASE{
		protected $_hostname = "localhost";
		protected $_hostuser ="root";
		protected $_hostpass ="";
		protected $_dbname = "mydb";
		protected $_connect;
		protected $_result;
		
		public function connection(){
			$this->_connect = mysql_connect($this->_hostname,$this->_hostuser, $this->_hostpass);
			mysql_select_db($this->_dbname, $this->_connect);
			mysql_query("SET NAMES 'utf8'");
		}
		
		public function disconnect(){
			if($this->_connect){
				mysql_close($this->_connect);	
			}	
		}
		
		public function query($sql){
			$this->_result = mysql_query($sql);
		}
		
		public function num_rows(){
			if($this->_result){
				$rows = mysql_num_rows($this->_result);
			}else{
				$rows = 0;	
			}
			return $rows;
		}
		
		public function fetch(){
			if($this->_result){
				$rows = mysql_fetch_assoc($this->_result);
			}else{
				$rows = 0;	
			}
			return $rows;
		}
	}
	
	function __autoload($class){
		require "models/".strtolower($class).".php";
		}
?>